package com.atguigu.gmall.order.consumer;

import com.atguigu.gmall.order.service.OrderInfoService;
import com.atguigu.gmall.rabbit.constant.MqConst;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: 李旭
 * @Time: 11:20
 * @Description:
 */
@Component
@RabbitListener(queues = MqConst.QUEUE_ORDER_CANCEL)
public class CancelOrderConsumer {


    @Autowired
    private OrderInfoService orderInfoService;
    //取消订单
    @RabbitHandler
    public void cancelOrder(Long orderId, Message message, Channel channel){
        try {

            //取消订单
            orderInfoService.cancelOrder(orderId);

            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
